package com.pioneer.app.dev.osuser.user;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Date;
import java.util.Properties;

public class AdminService {
	public static String USER_NAME="sysadmin";

	public Object getKeyValue(String key){
		InputStream in=
		this.getClass().getResourceAsStream("security.properties");
		Properties prop=new Properties();
		Object val=null;
		try {
			prop.load(in);
			val=prop.get(key);
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		return val;
	}
	
	public String getPWD(){
		return (String)this.getKeyValue("pwd");
	}
	
	public void editPassword(String pwd){
		//InputStream in=
			//this.getClass().getResourceAsStream("security.properties");
			Properties prop=new Properties();
			
			try {
				String filePath=this.getClass().getResource("security.properties").getFile();
				FileOutputStream out=new FileOutputStream(filePath.substring(1, filePath.length()));
				//prop.load(in);
				prop.setProperty("pwd", pwd);
				prop.save(out, ""+new Date().toLocaleString());
				out.flush();
				out.close();
			} catch (Exception e) {
				e.printStackTrace();
			}
	}
	public static AdminService _inst=new AdminService();
	
	public static AdminService getInst(){
		return _inst;
	}
	
	public static void main(String[]args){
		try{
			AdminService.getInst().editPassword("123456");
			
		}catch(Exception e){
			e.printStackTrace();
		}
	}
}
